package com.cloudcc.mobile.util;

import java.util.ArrayList;

import com.google.gson.Gson;

/**
 * 对象-json之前的转化
 * 
 * @author Administrator
 * @deprecated 操你妈的 那个王八蛋写的 额比
 */
public class Json {
	/**
	 * entity-json
	 * 
	 * @param object
	 * @return
	 */
	public static String toJson(Object object) {
		String obj = "";
		try {
			Gson gson = new Gson();
			obj = gson.toJson(object).toString();
		} catch (Exception e) {
			Tools.handle(e);
		}
		return obj;
	}

	/**
	 * json-entity
	 * 
	 * @param jsonString
	 * @param cls
	 * @return
	 */
	public static <T> Object toObject(String jsonString, Class<T> cls) {
		Gson gson = new Gson();
		Object object = gson.fromJson(jsonString, cls);
		return object;
	}

	public static String toJson(ArrayList<Object> list) {
		String json = "[";
		try {
			for (Object obj : list) {
				json = json + "{" + obj + "}";
			}
			json = json + "]";

		} catch (Exception e) {
			Tools.handle(e);
		}
		return json;
	}

	/**
	 * 判断是否是聊天
	 */

	public static boolean ischat(String message) {
		int a = message.indexOf("-");
		if (a != -1) {
			String id = message.substring(0, a);
			if (id.length() == 20) {
				return true;
			}
		}
		return false;
	}
}
